<template>
  <div id="wrapper">
    <!--<div class="top-header border-bottom fixed-top">-->
      <!--<div class="top-back"><a href="javascript:history.go(-1)"></a></div>-->
      <!--<h2 class="f36 ">APP新用户专享红包</h2>-->
    <!--</div>-->
    <div class="exbonus-main">
      <div :class="{'exltbnner-active':redpacketActive,exltbnner:!redpacketActive}"></div><!--exltbnner-active 领取后-->
      <div class="exlth-text f36" v-if="!redpacketActive">有{{redpacketList.length}}个红包等您领取</div>
      <div class="exlth-text f36" v-if="redpacketActive">您的红包已入账</div>
      <div class="exlth-btn" @click="reciveRP()"><a charset="xvtn"></a></div>
    </div>
    <!--弹窗-->
    <div class="axbonus-pop" v-if="coverShow">
      <div class="exltpop-box">
        <div class="exbox-titl f30">新用户专享</div>
        <!--<div class="exbox-dbcon">
            <div class="exbox-blist border mx-30 mb-20">
                <div class="sgbst-lpoer fl">
                    <div class="tenico color-fff ">APP专享</div>
                    <h2 class="font-arial f26 color-m1 text-center">¥<i class="fontbold mx-10">5</i></h2>
                    <p class="color-m1 text-center">满100元可用</p>
                </div>
                <div class="sgbst-center"></div>
               <div class="sgbst-rlker fr pt-15 px-15 ">
                    <div class="sbrk-titl f20 color-333"><i class="ico_z text-center color-fff f18 mr-15">帐号</i>限购部分游戏帐号类商品</div>
                    <div class="sbrk-tran f18 color-666">帐号交易</div>
                    <div class="sbrk-tnbtn color-999 fontarial">2017.09.15-2017.09.19</div>
                </div>
            </div>


        </div>-->
        <div class="dbgteen-dbcon mt-20">
          <div class="dbgtee-blist border mx-30 mb-20" v-for="item in redpacketList">
            <div class="sgbst-lpoer fl">
              <div class="appico f22 color-fff ">{{getTerminalModes(item.UseableTerminalModes)}}</div>
              <h2 class="font-arial f36 color-m1 text-center">¥<i class="fontbold mx-10">{{item.CouponValue}}</i></h2>
              <p class="color-m1 text-center f22">满{{item.MinMoney}}元可用</p>
            </div>
            <div class="sgbst-center"></div>
            <div class="sgbst-rlker fr p-20 pt-30 ">
              <div class="sbrk-titl f26 color-333"><i class="ico_z text-center color-fff f24 mr-15">{{getBizOfferTypes(item.UseableBizOfferTypes)}}</i>{{getGame(item.UseableGameList,item.UseableBizOfferTypes)}}</div>
              <div class="sbrk-tran f24 color-666">{{getServiceTypes(item.UseableTradingServiceTypes)}}</div>
              <div class="sbrk-tnbtn f20 color-999" v-if="!item.IsUseEffectNum">{{item.UseableFrom}}-{{item.UseableTo}}</div>
              <div class="sbrk-tnbtn f20 color-999" v-if="item.IsUseEffectNum">领取日起{{item.EffectiveNum}}天内有效</div>
            </div>
          </div>
        </div>
        <div class="sgbt-text f28 color-fff text-center">红包已放置账户</div>

      </div>
      <div class="sgbt-close"><a class="btslo" @click="coverShow = false"></a></div>
    </div>
    <div class="dialog_cover" v-if="coverShow"></div>
  </div>
</template>
<script>
  export default{
    data(){
      return{
        coverShow:false,
          redpacketActive:false,
          redpacketList:[],
          wantedList:["CR20171106164208","CR20171106173537","CR20171106163300","CR20171106174136","CR20171106174331","CR20171106174546"],
      }
    },
    components:{

    },
    watch:{

    },
    created(){
    this.getParams()
    },
    mounted(){
    this.getRedPacketList()
    },
    methods:{
      getParams(){
          var self= this;
          document.title = 'APP新用户专享红包';
        var url = location.search;
        self.thisLocation = location.href.split("?")[0];
        var req = new Object();
        if (url.indexOf("?") != -1){
            var strs;
            var str = url.substr(1);
            strs = str.split("&");
            for(var i=0;i<strs.length;i++){
                req[strs[i].split("=")[0]]=(strs[i].split("=")[1])
            }

        }else {

        }
      },
        getReciveRPList(){
          var self = this;

        },
        getRedPacketList(){
          var self = this;
            self.$getAccount().then(account=>{
                if(account!=null){
                    self.$http.post(
                        self.$CONSTANTS.APIGoods + 'coupon/getRuleCouponsLogin',
                        {
                            "game_id":"YX16111014302332100001",
                            "bizoffertype_id":"0,1,2,10",
                            "terminal_mode":"1,2",
                            "trading_type":"1,2,5,40,42,47",
                            "coupon_grade":"2"
                        }
                    ).then(
                        (res)=>{
                            if(res.body.result){
                                var list = JSON.parse(res.body.result);
                                console.log(list);
                                for (var i = 0;i<list.length;i++){
                                    for (var j = 0;j<self.wantedList.length;j++){
                                        if (list[i].GroupId == self.wantedList[j]){
                                            console.log(list[i].IsReceivedCoupon)
                                            if(list[i].IsReceivedCoupon){
                                                self.redpacketActive = true
                                                self.redpacketList.push(list[i])
                                            }else {
                                                self.redpacketList.push(list[i])
                                                console.log("1111111",self.redpacketList)
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    )
                }else {
                    self.$http.post(
                        self.$CONSTANTS.APIGoods + 'coupon/getRuleCouponsNOTLogin',
                        {
                            "game_id":"YX16111014302332100001",
                            "bizoffertype_id":"0,1,2,10",
                            "terminal_mode":"1,2",
                            "trading_type":"1,2,5,40,42,47",
                            "coupon_grade":"2"
                        }
                    ).then(
                        (res)=>{
                            if(res.body.result){
                                var list = JSON.parse(res.body.result);
                                self.allRPlist = list;
                                for (var i = 0;i<list.length;i++){
                                    for (var j = 0;j<self.wantedList.length;j++){
                                        if (list[i].GroupId == self.wantedList[j]){
                                            self.redpacketList.push(list[i])
                                        }
                                    }
                                }
                            }
                        }
                    )
                }
            })
        },
        reciveRP(){
            var self = this;
            self.$getAccount().then(account=>{
                if(account!=null){
                    console.log(self.redpacketList)
                    for (var i = 0; i<self.redpacketList.length; i++){
                        self.$http.post(self.$CONSTANTS.APIGoods + 'coupon/receiveCouponToUser',
                            {
                                coupon_rule_id:self.redpacketList[i].GroupId
                            }
                        ).then(
                            ()=>{
                                self.coverShow = true,
                                    self.redpacketActive = true,
                                    console.log("领取红包id"+self.redpacketList[i-1].GroupId+"成功")
                            }

                        )
                    }
                }else {
                    location.href = "/vue/login?returnUrl=" + encodeURIComponent(location.href);
                }
            })
        },
        getTerminalModes(UseableTerminalModes){
            var str = '全站通用'
            var modesMap = {
                0:'电脑版',1:'触屏版',2:'APP'
            }
            if(UseableTerminalModes){
                var list = UseableTerminalModes.split(',')
                if(list.length<3){
                    var temp =[]
                    list.forEach(function (item) {
                        temp.push(modesMap[item])
                    })
                    str =  temp.join("\\") + '专享'
                }
            }
            return str
        },
        getGame(UseableGameList,UseableBizOfferTypes ){
            var str = '限购部分游戏帐号类商品'
            var getBizOfferTypes = this.getBizOfferTypes(UseableBizOfferTypes,true)
            if(getBizOfferTypes!='全部商品类型'){
                getBizOfferTypes = getBizOfferTypes +'类商品'
            }
            if(UseableGameList){
                if(UseableGameList.split(',').length==1){
                    str = '限购'+this.goodsEO.gameName+getBizOfferTypes
                }
            }else {
                str = '支持全部游戏'+getBizOfferTypes
            }
            return str
        },
        getBizOfferTypes  (UseableBizOfferTypes,all){
            var str = '通用'
            if(all){
                str = '全部商品类型'
            }
            var modesMap = {
                0:'装备',1:'游戏币',2:'帐号',3:'代练',
                4:'包裹',5:'点卡',6:'网店',7:'密保卡',
                8:'激活码',9:'手机充值卡',10:'其他',11:'元宝类',
                12:'互换'
            }
            if(UseableBizOfferTypes){
                var list = UseableBizOfferTypes.split(',')
                if(list.length<13){
                    var temp =[]
                    list.forEach(function (item) {
                        temp.push(modesMap[item])
                    })
                    str =  temp.join(',')
                }
            }
            return str
        },
        getServiceTypes  (UseableTradingServiceTypes){
            var str = '支持所有交易方式'
            var modesMap = {
                0:'端游自助',1:'端游担保',2:'端游寄售',3:'API`',
                4:'点卡类',5:'端游帐号',6:'商城',7:'消费券',
                8:'工具',9:'代练',10:'未定义',11:'51淘',
                12:'施乐会',13:'7宝',14:'658',15:'活动',
                16:'赠金',17:'消息中心',18:'台服085',19:'173库存系统',
                20:'平放开台',21:'积分频道',22:"彩票",23:'点卡商城',
                24:'平放开台',25:'积分频道',26:"5173助理",27:'9517 B2B',
                28:'帐号租赁',29:'手游交易',30:"直通车",31:'打赏',
                32:'视频真人秀',33:'卖家保险',34:"网页游戏开服表",35:'点卡换金',
                36:'点卡保险',37:'点卡竞价',38:"金牌掌柜",39:'658金融网',
                40:'(游戏币)金币商城',41:'高尔夫',42:"手游",43:'游戏币回购',
                44:'巨人合作金币',45:'退游宝',46:"金钻",47:'触屏版M站',
                48:'饰品交易'
            }
            if(UseableTradingServiceTypes){
                var list = UseableTradingServiceTypes.split(',')
                if(list.length<13){
                    var temp =[]
                    list.forEach(function (item) {
                        temp.push(modesMap[item])
                    })
                    str =  temp.join(',')+'商品交易'
                }
            }
            return str
        },
        getTime(UseableFrom,UseableTo,EffectiveNum){
            var str = '';
            if(UseableFrom){
                UseableFrom=UseableFrom.replace(/^(\d{4})(\d{2})(\d{2})$/, "$1.$2.$3");
                UseableTo=UseableTo.replace(/^(\d{4})(\d{2})(\d{2})$/, "$1.$2.$3");
                str = UseableFrom + "-"+ UseableTo
            }else{
//                	var nowDate = new Date();
//                	var endTime = new Date(EffectiveNum*24*60*60*1000+nowDate.getTime())
//	                str = nowDate.getFullYear()+'.'+(nowDate.getMonth()+1)+'.'+nowDate.getDate()+'-'+endTime.getFullYear()+'.'+(endTime.getMonth()+1)+'.'+endTime.getDate()
                str = '领取后'+EffectiveNum+'天内有效'
            }
            return str
        },
      }
  }
</script>
<style>
  @import "../../assets/css/fost-base.css";
  @import "../../assets/css/activities/exbonus.css";
</style>
